## This is the code to create the coefficient plot
library(ggplot2)
model1 <- as.data.frame(precis(n.notes.gp.only.female.indiv ))
model1 <-model1[c(2:3),] # This is different because doesn't have extra sigmasq parameter
model2 <- as.data.frame(precis(notefreq.gp.cov.female.indiv))
model2 <-model2[c(2:7),]
model3 <- as.data.frame(precis(notedur.gp.only.female.indiv))
model3 <-model3[c(2:4),]
model5 <- as.data.frame(precis(noterate.gp.only.male.indiv))
model5 <-model5[c(2:4),]
# N notes spatial
1.09/ (1.09+0.07)
# Note freq spatial
0.56 /(0.56+0.56)
# Note duration spatial
2.23 /(2.23+0.38)
# Note rate spatial
0.77 / (0.77+1.56)
# Put model estimates into temporary data.frames:
model1Frame <- data.frame(Variable = rownames(model1),
Coefficient = model1$mean,
ymin = model1$`5.5%`,
ymax =model1$`94.5%`,
modelName = "Female Number of Notes")
model2Frame <- data.frame(Variable = rownames(model2),
Coefficient = model2$mean,
ymin = model2$`5.5%`,
ymax =model2$`94.5%`,
modelName = "Female Note 1 Max Frequency")
model3Frame <- data.frame(Variable = rownames(model3),
Coefficient = model3$mean,
ymin = model3$`5.5%`,
ymax =model3$`94.5%`,
modelName = "Female Note 1 Duration")
model5Frame <- data.frame(Variable = rownames(model5),
Coefficient = model5$mean,
ymin = model5$`5.5%`,
ymax =model5$`94.5%`,
modelName = "Male Note Rate")
# Combine these data.frames
allModelFrame <- data.frame(rbind(model1Frame,model2Frame,model3Frame,model5Frame)) # etc.
# Plot
zp1 <- ggplot(allModelFrame, aes(colour = modelName))
zp1 <- zp1 + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
# zp1 <- zp1 + geom_linerange(aes(x = Variable, ymin = Coefficient - SE*interval1,
# ymax = Coefficient + SE*interval1),
# lwd = 1, position = position_dodge(width = 1/2))
zp1 <- zp1 + geom_pointrange(aes(x = Variable, y = Coefficient, ymin = ymin,
ymax = ymax),
lwd = 1/2, position = position_dodge(width = 1/2),
shape = 21, fill = "WHITE") + scale_color_manual(values=c(viridis::viridis(4,end=0.8)))
zp1 <- zp1 + coord_flip() + theme_bw()+ theme(legend.title=element_blank())+ xlab("")
zp1 <- zp1 + ggtitle("")
zp1 <- zp1 + scale_x_discrete(labels=c("Eta-squared", "Rho-squared", "Mainland (0) or Island (1)","Temperature (C)","Rainfall (mm)", "Sigma-squared"))
print(zp1) # The trick to these is position_dodge().
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.